//引入vue
import Vue from 'vue';

//导入 vee-validate 验证库
import VeeValidate,{Validator} from 'vee-validate';

//导入中文语言包
import zh from 'vee-validate/dist/locale/zh_CN';
// 使用插件
Vue.use(VeeValidate);
Validator.localize('zh', zh);

// 导入正则
import {phoneReg,codeReg,pwdReg} from '@/utils/index'

// 手机号的验证规则
Validator.extend('phone',{
    // 验证规则，value是我们输入的值
    // field是验证失败的回调
    getMessage:field => '请输入正确的'+ field,
    validate: value => phoneReg.test(value)
})


//验证必要性的规则
Validator.extend('required', {
    getMessage: field => field + "不能为空!",
    validate: value => value
});

//验证码的验证规则
Validator.extend('code', {
    getMessage: field => "请输入正确的" + field,
    validate: value => codeReg.test(value)
});


//密码的验证规则
Validator.extend('pwd', {
    getMessage: field => "请输入正确的" + field,
    validate: value => pwdReg.test(value)
});


//重复密码的验证规则
Validator.extend('ispwd', {
    getMessage: field =>  field + "不一致！",
    validate: (value,args) => value === args[0]
       
});


//协议规则
Validator.extend('agree', {
    getMessage: field =>  "请勾选" + field,
    validate: value => value
});

